/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dao;

import java.util.List; 
import dto.LoaiNguoiDung; 
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import util.ConnectToMySql;
 
public class LoaiNguoiDungDAO {
    public static List<LoaiNguoiDung> LayDSLoaiNguoiDung() throws ClassNotFoundException, InstantiationException, IllegalAccessException, SQLException{
         List<LoaiNguoiDung> listLoaiNguoiDung = new ArrayList<LoaiNguoiDung>();

        Connection conn = ConnectToMySql.getConnection();
        if (conn != null) {
            try {
                CallableStatement cs = conn.prepareCall("select * from LoaiNguoiDung");
                 ResultSet rs = cs.executeQuery();
                if (rs != null) {
                    while (rs.next()) {
                        LoaiNguoiDung s = new LoaiNguoiDung();
                        s.setMaloainguoidung(rs.getInt("maloainguoidung"));
                        s.setTenloainguoidung(rs.getString("tenloainguoidung"));
                        s.setTrangthai(rs.getInt("trangthai")); 
                        listLoaiNguoiDung.add(s);
                    }
                }
            } catch (Exception ex) {
                System.out.println(ex);
                return null;
            }
        }

        return listLoaiNguoiDung;
    }
    
    public static LoaiNguoiDung LayThongTinLoaiNguoiDung(int maLoaiNguoiDung)throws ClassNotFoundException, InstantiationException, IllegalAccessException, SQLException{
        LoaiNguoiDung loai = new  LoaiNguoiDung();

        Connection conn = ConnectToMySql.getConnection();
        if (conn != null) {
            try {
                CallableStatement cs = conn.prepareCall("select * from LoaiNguoiDung where maloainguoidung=?");
                cs.setInt(1, maLoaiNguoiDung);
                 ResultSet rs = cs.executeQuery();
                if (rs != null) {
                    while (rs.next()) {
                        LoaiNguoiDung s = new LoaiNguoiDung();
                        s.setMaloainguoidung(rs.getInt("maloainguoidung"));
                        s.setTenloainguoidung(rs.getString("tenloainguoidung"));
                        s.setTrangthai(rs.getInt("trangthai"));  
                        loai= s;
                    }
                }
            } catch (Exception ex) {
                System.out.println(ex);
                return null;
            }
        }

        return loai;
    }
}
